package com.zhouxiaoge.transaction.user.web;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.zhouxiaoge.transaction.user.dao.CustomerRepository;
import com.zhouxiaoge.transaction.user.domain.Customer;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/customer")
public class CustomerResource {

    private final CustomerRepository customerRepository;

    public CustomerResource(CustomerRepository customerRepository) {
        this.customerRepository = customerRepository;
    }

    @PostMapping
    public Customer create(@RequestBody Customer customer) {
        return customerRepository.save(customer);
    }

    @GetMapping
    @HystrixCommand
    public List<Customer> getAll() {
        return customerRepository.findAll();
    }
}
